home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Extensions / img / mppmcmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  2.4 KB  |  75 lines  |  [TEXT/CWIE]

  1. /* mppmcmap.h - header file for colormap routines in python img version
  2. ** of ppm routines.
  3. **
  4. ** Unfortunately, the routines cannot be shared with libppm (which is probably
  5. ** also loaded if these routines are used), because
  6. ** 1. Pixel format is different
  7. ** 2. Storage of images is different (2-dimensional vs 1-dim array).
  8. */
  9.  
  10. typedef long pixel;
  11. typedef unsigned char pixval;
  12.  
  13. #define MAXVAL 255
  14.  
  15. #define MPPM_GETR(x) ((x)&0xff)
  16. #define MPPM_GETG(x) (((x)>>8) & 0xff)
  17. #define MPPM_GETB(x) (((x)>>16) & 0xff)
  18. #define MPPM_ASSIGN(p,red,grn,blu) \
  19.     (p) = ((pixel) (red)) | ((pixel) (grn) << 8) | ((pixel) (blu) << 16)
  20. #define MPPM_EQUAL(p,q) ((p) == (q))
  21. #define MPPM_LUMIN(p) \
  22.     (0.299*MPPM_GETR(p) + 0.587*MPPM_GETG(p) + 0.114*MPPM_GETB(p))
  23.  
  24.  
  25. /* Color histogram stuff. */
  26.  
  27. typedef struct colorhist_item* colorhist_vector;
  28. struct colorhist_item
  29.     {
  30.     pixel color;
  31.     int value;
  32.     };
  33.  
  34. typedef struct colorhist_list_item* colorhist_list;
  35. struct colorhist_list_item
  36.     {
  37.     struct colorhist_item ch;
  38.     colorhist_list next;
  39.     };
  40.  
  41. /* External interface (from dither.c and genmap.c): */
  42. int mppm_genmap Py_PROTO((long *pixels, int cols, int rows,
  43.               long *colormap, int colormapsize));
  44.  
  45. int mppm_dither Py_PROTO((long *pixels, int cols, int rows,
  46.              long *colormap, int colormapsize, int floyd,
  47.              unsigned char *result));
  48.  
  49. /* Internal interfaces (from mppm3.c) */
  50. colorhist_vector mppm_computecolorhist Py_PROTO(( pixel* pixels, int cols, int rows, int maxcolors, int* colorsP ));
  51. /* Returns a colorhist *colorsP long (with space allocated for maxcolors. */
  52.  
  53. void mppm_addtocolorhist Py_PROTO(( colorhist_vector chv, int* colorsP, int maxcolors, pixel* colorP, int value, int position ));
  54.  
  55. void mppm_freecolorhist Py_PROTO(( colorhist_vector chv ));
  56.  
  57.  
  58. /* Color hash table stuff. */
  59.  
  60. typedef colorhist_list* colorhash_table;
  61.  
  62. colorhash_table mppm_computecolorhash Py_PROTO(( pixel* pixels, int cols, int rows, int maxcolors, int* colorsP ));
  63.  
  64. int mppm_lookupcolor Py_PROTO(( colorhash_table cht, pixel* colorP ));
  65.  
  66. colorhist_vector mppm_colorhashtocolorhist Py_PROTO(( colorhash_table cht, int maxcolors ));
  67. colorhash_table mppm_colorhisttocolorhash Py_PROTO(( colorhist_vector chv, int colors ));
  68.  
  69. int mppm_addtocolorhash Py_PROTO(( colorhash_table cht, pixel* colorP, int value ));
  70. /* Returns -1 on failure. */
  71.  
  72. colorhash_table mppm_alloccolorhash Py_PROTO(( void ));
  73.  
  74. void mppm_freecolorhash Py_PROTO(( colorhash_table cht ));
  75.